/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Registro.java
 *
 * Created on Apr 25, 2009, 1:36:57 AM
 */
package dialogs;

import util.CategoriaNode;
import util.CategoriaListCellRenderer;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JTabbedPane;
import persistencia.controller.jpa.CategoriaJpaController;
import persistencia.controller.jpa.RegistroJpaController;
import persistencia.controller.jpa.exceptions.NonexistentEntityException;
import persistencia.entidade.Categoria;
import persistencia.entidade.Registro;
import util.TextFieldMaxLenth;

/**
 *
 * @author Novo usuário
 */
public class TelaRegistro extends javax.swing.JPanel {

    private Registro registro;
    private TabelaRegistros tbReg;
    private MobCatTree tree;
    private static String[] estados = {"--", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RR", "RO", "RJ", "RN", "RS", "SC", "SP", "SE", "TO"};
    private RegistroJpaController regJpa = new RegistroJpaController();

    public TelaRegistro(Registro registro, TabelaRegistros tbReg, MobCatTree tree) {
        this.registro = registro;
        initComponents();
        txNome.setText(registro.getNome());
        this.tbReg = tbReg;
        this.tree = tree;
        lstCatAtuais.setCellRenderer(new CategoriaListCellRenderer());
        lstOutrasCats.setCellRenderer(new CategoriaListCellRenderer());

        txNome.setText(registro.getNome());
        txBairro.setText(registro.getBairro());
        txEmail.setText(registro.getEmail());
        txRua.setText(registro.getEndereco());
        txResumoMob.setText(registro.getResumoMob());
        txResumoWeb.setText(registro.getResumoWeb());
        txtSite.setText(registro.getSite());
        txTelefone1.setText(registro.getTelefone());
        txTelefone2.setText(registro.getTelefone2());
        txTextoMob.setText(registro.getTextoMob());
        txTextoWeb.setText(registro.getTextoWeb());
        if(registro.getNumero() != null){
            txNumero.setText(registro.getNumero().toString());
        }
        imgIconeMob.setImagem(registro.getIconeMob());
        imgIconeWeb.setImagem(registro.getIconeWeb());

        cbPeso.setSelectedItem(registro.getPeso());

        List<String> cidades = regJpa.getCidadesDistinct();
        for (int i = 0; i < cidades.size(); i++) {
            String cidade = cidades.get(i);
            if (cidade != null && !cidade.isEmpty()) {
                cbCidade.addItem(cidade);
            }
        }
        if (registro.getCidade() != null) {
            cbCidade.setSelectedItem(registro.getCidade());
        }

        List<String> estados = regJpa.getUFDistinct();
        for (int i = 0; i < estados.size(); i++) {
            String estado = estados.get(i);
            if (estado != null) {
                if (!estado.isEmpty()) {
                    cbEstado.addItem(estado);
                }
            }
        }
        if (registro.getUf() != null) {
            cbEstado.setSelectedItem(registro.getUf());
        }

        List<String> ddds = regJpa.getDDDDistinct();
        for (int i = 0; i < ddds.size(); i++) {
            String ddd = ddds.get(i);
            if (ddd != null) {
                if (!ddd.isEmpty()) {
                    cbDDD.addItem(ddd);
                }
            }
        }
        if (registro.getDdd() != null) {
            cbDDD.setSelectedItem(registro.getDdd());
        }
        loadCategoriaList();
    }

    private void loadCategoriaList() {

        lstCatAtuais.setListData(registro.getCategoriaCollection().toArray());

        List<Categoria> catsSemFilhas = new CategoriaJpaController().findCategoriaEntitiesSemFilhas();
        DefaultListModel listModel = new DefaultListModel();
        for (Iterator<Categoria> itCatSemFilha = catsSemFilhas.iterator(); itCatSemFilha.hasNext();) {
            Categoria catNova = itCatSemFilha.next();
            List<Categoria> categorias = registro.getCategoriaCollection();
            boolean find = false;
            for (Iterator<Categoria> it2 = categorias.iterator(); it2.hasNext();) {
                Categoria categoria = it2.next();
                if (categoria.getCategoriaId().intValue() == catNova.getCategoriaId().intValue()) {
                    find = true;
                }
            }
            if (!find) {
                listModel.addElement(catNova);
            }
        }
        if (tbReg != null) {
            tbReg.loadTable();
        }
        lstOutrasCats.setModel(listModel);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        btnFechar = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        tbGeral = new javax.swing.JPanel();
        cbPeso = new javax.swing.JComboBox();
        txtSite = new javax.swing.JTextField();
        txEmail = new javax.swing.JTextField();
        txNome = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        txTextoWeb = new javax.swing.JTextArea();
        jLabel17 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        txTextoMob = new javax.swing.JTextArea();
        jLabel18 = new javax.swing.JLabel();
        jPanel12 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txResumoMob = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        txResumoWeb = new javax.swing.JTextArea();
        jLabel16 = new javax.swing.JLabel();
        tbEndereco = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txRua = new javax.swing.JTextField();
        txNumero = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txBairro = new javax.swing.JTextField();
        cbCidade = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cbEstado = new javax.swing.JComboBox(estados);
        btMapa = new javax.swing.JButton();
        imagePanel1 = new dialogs.ImagePanel();
        tabImagem = new javax.swing.JPanel();
        imgIconeMob = new dialogs.ImagePanelDlg("Ícone para celular", registro.getIconeMob(), "Tamanho 18x18\nImagem png");
        imgImagemMob = new dialogs.ImagePanelDlg("Imagem para celular", registro.getImgMob(), "Tamnho 100x100\nTipo png");
        imgIconeWeb = new dialogs.ImagePanelDlg("Ícone da pagina de internet", registro.getIconeWeb(), "Tamanho 30x30");
        imgImagemWeb = new dialogs.ImagePanelDlg("Imagem da pagina de internet", registro.getImgWeb(), "Tamanho 200x200");
        tabCategoria = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstCatAtuais = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        lstOutrasCats = new javax.swing.JList();
        btnRemoverCategoria = new javax.swing.JButton();
        btnAdicionarCategoria = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        tabTelefone = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        txTelefone1 = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txTelefone2 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cbDDD = new javax.swing.JComboBox();

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(856, 391));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        );

        setName("Form"); // NOI18N
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(1123, 391));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new FlowLayout(FlowLayout.RIGHT));
        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(mobcatadmin.MobCatAdminApp.class).getContext().getResourceMap(TelaRegistro.class);
        btnFechar.setText(resourceMap.getString("btnFechar.text")); // NOI18N
        btnFechar.setActionCommand(resourceMap.getString("btnFechar.actionCommand")); // NOI18N
        btnFechar.setName("btnFechar"); // NOI18N
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });

        btnSalvar.setLabel(resourceMap.getString("btnSalvar.label")); // NOI18N
        btnSalvar.setName("btnSalvar"); // NOI18N
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(655, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSalvar)
                    .addComponent(btnFechar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        tbGeral.setName("tbGeral"); // NOI18N
        tbGeral.setPreferredSize(new java.awt.Dimension(500, 600));

        cbPeso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        cbPeso.setName("cbPeso"); // NOI18N

        txtSite.setText(resourceMap.getString("txtSite.text")); // NOI18N
        txtSite.setName("txtSite"); // NOI18N
        txtSite.setDocument(new TextFieldMaxLenth(250));

        txEmail.setText(resourceMap.getString("txEmail.text")); // NOI18N
        txEmail.setDocument(new TextFieldMaxLenth(250));
        txEmail.setName("txEmail"); // NOI18N

        txNome.setText(resourceMap.getString("txNome.text")); // NOI18N
        txNome.setDocument(new TextFieldMaxLenth(250));
        txNome.setName("txNome"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jPanel7.setName("jPanel7"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        txTextoWeb.setColumns(20);
        txTextoWeb.setRows(5);
        txTextoWeb.setName("txTextoWeb"); // NOI18N
        jScrollPane5.setViewportView(txTextoWeb);

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        txTextoMob.setColumns(20);
        txTextoMob.setRows(5);
        txTextoMob.setName("txTextoMob"); // NOI18N
        txTextoMob.setDocument(new TextFieldMaxLenth(256));
        jScrollPane6.setViewportView(txTextoMob);

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel17))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
                            .addComponent(jLabel18)))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel12.setName("jPanel12"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txResumoMob.setColumns(20);
        txResumoMob.setRows(5);
        txResumoMob.setDocument(new TextFieldMaxLenth(50));
        txResumoMob.setName("txResumoMob"); // NOI18N
        jScrollPane1.setViewportView(txResumoMob);

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        txResumoWeb.setColumns(20);
        txResumoWeb.setRows(5);
        txResumoWeb.setName("txResumoWeb"); // NOI18N
        jScrollPane2.setViewportView(txResumoWeb);

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        javax.swing.GroupLayout tbGeralLayout = new javax.swing.GroupLayout(tbGeral);
        tbGeral.setLayout(tbGeralLayout);
        tbGeralLayout.setHorizontalGroup(
            tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tbGeralLayout.createSequentialGroup()
                .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tbGeralLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txNome, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txEmail, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(tbGeralLayout.createSequentialGroup()
                                .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(51, 51, 51)
                                .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9))
                                .addGap(10, 10, 10))))
                    .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(tbGeralLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))))
                .addContainerGap(95, Short.MAX_VALUE))
        );
        tbGeralLayout.setVerticalGroup(
            tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tbGeralLayout.createSequentialGroup()
                .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tbGeralLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(tbGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tbGeralLayout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel16)
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("tbGeral.TabConstraints.tabTitle"), tbGeral); // NOI18N

        tbEndereco.setName("tbEndereco"); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel3.border.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(800, 116));

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txRua.setText(resourceMap.getString("txRua.text")); // NOI18N
        txRua.setName("txRua"); // NOI18N
        txRua.setDocument(new TextFieldMaxLenth(250));

        txNumero.setText(resourceMap.getString("txNumero.text")); // NOI18N
        txNumero.setName("txNumero"); // NOI18N
        txNumero.setDocument(new TextFieldMaxLenth(10));

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        txBairro.setText(resourceMap.getString("txBairro.text")); // NOI18N
        txBairro.setName("txBairro"); // NOI18N
        txBairro.setDocument(new TextFieldMaxLenth(250));

        cbCidade.setEditable(true);
        //cbCidade.setDocument(new TextFieldMaxLenth(100));
        cbCidade.setName("cbCidade"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        cbEstado.setEditable(true);
        cbEstado.setName("cbEstado"); // NOI18N
        //cbEstado.setDocument(new TextFieldMaxLenth(2));

        btMapa.setText(resourceMap.getString("btMapa.text")); // NOI18N
        btMapa.setName("btMapa"); // NOI18N
        btMapa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMapaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txRua, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbEstado, 0, 51, Short.MAX_VALUE)
                                    .addComponent(jLabel6)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txNumero)
                                    .addComponent(jLabel3))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addGap(109, 109, 109))
                                    .addComponent(txBairro, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))))
                        .addGap(27, 27, 27)
                        .addComponent(btMapa)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btMapa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        imagePanel1.setBackground(resourceMap.getColor("imagePanel1.background")); // NOI18N
        imagePanel1.setName("imagePanel1"); // NOI18N

        javax.swing.GroupLayout imagePanel1Layout = new javax.swing.GroupLayout(imagePanel1);
        imagePanel1.setLayout(imagePanel1Layout);
        imagePanel1Layout.setHorizontalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 173, Short.MAX_VALUE)
        );
        imagePanel1Layout.setVerticalGroup(
            imagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 161, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout tbEnderecoLayout = new javax.swing.GroupLayout(tbEndereco);
        tbEndereco.setLayout(tbEnderecoLayout);
        tbEnderecoLayout.setHorizontalGroup(
            tbEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tbEnderecoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imagePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(329, Short.MAX_VALUE))
        );
        tbEnderecoLayout.setVerticalGroup(
            tbEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tbEnderecoLayout.createSequentialGroup()
                .addGroup(tbEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tbEnderecoLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(imagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tbEnderecoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("tbEndereco.TabConstraints.tabTitle"), tbEndereco); // NOI18N

        tabImagem.setName("tabImagem"); // NOI18N

        imgIconeMob.setName("imgIconeMob"); // NOI18N

        imgImagemMob.setName("imgImagemMob"); // NOI18N

        imgIconeWeb.setName("imgIconeWeb"); // NOI18N

        imgImagemWeb.setName("imgImagemWeb"); // NOI18N

        javax.swing.GroupLayout tabImagemLayout = new javax.swing.GroupLayout(tabImagem);
        tabImagem.setLayout(tabImagemLayout);
        tabImagemLayout.setHorizontalGroup(
            tabImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabImagemLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabImagemLayout.createSequentialGroup()
                        .addComponent(imgIconeMob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imgIconeWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabImagemLayout.createSequentialGroup()
                        .addComponent(imgImagemMob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imgImagemWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(240, Short.MAX_VALUE))
        );
        tabImagemLayout.setVerticalGroup(
            tabImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabImagemLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(imgIconeMob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(imgIconeWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabImagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(imgImagemMob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(imgImagemWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("tabImagem.TabConstraints.tabTitle"), tabImagem); // NOI18N

        tabCategoria.setName("tabCategoria"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        lstCatAtuais.setName("lstCatAtuais"); // NOI18N
        jScrollPane3.setViewportView(lstCatAtuais);

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        lstOutrasCats.setName("lstOutrasCats"); // NOI18N
        jScrollPane4.setViewportView(lstOutrasCats);

        btnRemoverCategoria.setText(resourceMap.getString("btnRemoverCategoria.text")); // NOI18N
        btnRemoverCategoria.setName("btnRemoverCategoria"); // NOI18N
        btnRemoverCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverCategoriaActionPerformed(evt);
            }
        });

        btnAdicionarCategoria.setText(resourceMap.getString("btnAdicionarCategoria.text")); // NOI18N
        btnAdicionarCategoria.setName("btnAdicionarCategoria"); // NOI18N
        btnAdicionarCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarCategoriaActionPerformed(evt);
            }
        });

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        javax.swing.GroupLayout tabCategoriaLayout = new javax.swing.GroupLayout(tabCategoria);
        tabCategoria.setLayout(tabCategoriaLayout);
        tabCategoriaLayout.setHorizontalGroup(
            tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCategoriaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnRemoverCategoria, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnAdicionarCategoria, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(475, Short.MAX_VALUE))
        );
        tabCategoriaLayout.setVerticalGroup(
            tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabCategoriaLayout.createSequentialGroup()
                .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabCategoriaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(tabCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane4)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)))
                    .addGroup(tabCategoriaLayout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addComponent(btnRemoverCategoria)
                        .addGap(18, 18, 18)
                        .addComponent(btnAdicionarCategoria)))
                .addContainerGap(116, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("tabCategoria.TabConstraints.tabTitle"), tabCategoria); // NOI18N

        tabTelefone.setName("tabTelefone"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        txTelefone1.setText(resourceMap.getString("txTelefone1.text")); // NOI18N
        txTelefone1.setName("txTelefone1"); // NOI18N
        txTelefone1.setDocument(new TextFieldMaxLenth(8));

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        txTelefone2.setText(resourceMap.getString("txTelefone2.text")); // NOI18N
        txTelefone2.setName("txTelefone2"); // NOI18N
        txTelefone2.setDocument(new TextFieldMaxLenth(8));

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        cbDDD.setEditable(true);
        cbDDD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "21", "22", "11", "12", "23", "14" }));
        cbDDD.setName("cbDDD"); // NOI18N

        javax.swing.GroupLayout tabTelefoneLayout = new javax.swing.GroupLayout(tabTelefone);
        tabTelefone.setLayout(tabTelefoneLayout);
        tabTelefoneLayout.setHorizontalGroup(
            tabTelefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabTelefoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabTelefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addComponent(txTelefone2, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                    .addComponent(jLabel10)
                    .addComponent(cbDDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTelefone1))
                .addContainerGap(724, Short.MAX_VALUE))
        );
        tabTelefoneLayout.setVerticalGroup(
            tabTelefoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabTelefoneLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txTelefone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txTelefone2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbDDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(214, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("tabTelefone.TabConstraints.tabTitle"), tabTelefone); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 875, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(395, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(50, 50, 50)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)))
        );

        add(jPanel4);
    }// </editor-fold>//GEN-END:initComponents

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
        ((JTabbedPane) this.getParent()).remove(this);
    }//GEN-LAST:event_btnFecharActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        try {
            Cursor c = jPanel2.getCursor();
            this.setCursor(new Cursor(Cursor.WAIT_CURSOR));

            registro.setNome(txNome.getText());
            registro.setBairro(txBairro.getText());
            registro.setCidade((String) cbCidade.getSelectedItem());
            registro.setDdd((String) cbDDD.getSelectedItem());
            registro.setEmail(txEmail.getText());
            registro.setEndereco(txRua.getText());
            if(!txNumero.getText().isEmpty()){
                registro.setNumero(Integer.parseInt(txNumero.getText()));
            }
            registro.setIconeMob(imgIconeMob.getImagem());
            registro.setIconeWeb(imgIconeWeb.getImagem());
            registro.setImgMob(imgImagemMob.getImagem());
            registro.setImgWeb(imgImagemWeb.getImagem());

            if (cbPeso.getSelectedItem() != null) {
                registro.setPeso(Integer.parseInt((String) cbPeso.getSelectedItem()));
            }
            registro.setResumoMob(txResumoMob.getText());
            registro.setResumoWeb(txResumoWeb.getText());
            registro.setSite(txtSite.getText());
            registro.setTelefone(txTelefone1.getText());
            registro.setTelefone2(txTelefone2.getText());
            registro.setTextoMob(txTextoMob.getText());
            registro.setTextoWeb(txTextoWeb.getText());
            registro.setTextoWeb(txTextoWeb.getText());
            registro.setUf((String) cbEstado.getSelectedItem());

            if (registro.getRegistroId() != null) {
                regJpa.edit(registro);
            } else {
                regJpa.create(registro);
            }

            ((JTabbedPane) this.getParent()).remove(this);
            this.setCursor(c);
            if (tbReg != null) {
                tbReg.loadTable();
            }
            List<Categoria> cats = registro.getCategoriaCollection();
            for (Iterator<Categoria> it = cats.iterator(); it.hasNext();) {
                Categoria categoria = it.next();
                if (categoria.getCategoriaPai() != null) {
                    ((MobCatTreeModel) tree.getTree().getModel()).loadSubCat(new CategoriaNode(categoria.getCategoriaPai()));
                }
            }


        } catch (NonexistentEntityException ex) {
            Logger.getLogger(TelaRegistro.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(TelaRegistro.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnRemoverCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverCategoriaActionPerformed

        Object[] cats = lstCatAtuais.getSelectedValues();
        List<Categoria> catReg = registro.getCategoriaCollection();
        List<Categoria> newCateReg = new ArrayList<Categoria>();
        for (Iterator<Categoria> it = catReg.iterator(); it.hasNext();) {
            Categoria categoria = it.next();
            boolean find = false;
            for (int i = 0; i < cats.length; i++) {
                Categoria cat = (Categoria) cats[i];
                if (categoria.getCategoriaId().intValue() == cat.getCategoriaId().intValue()) {
                    find = true;
                }
            }
            if (!find) {
                newCateReg.add(categoria);
            }
        }
        registro.setCategoriaCollection(newCateReg);
        loadCategoriaList();
}//GEN-LAST:event_btnRemoverCategoriaActionPerformed

    private void btnAdicionarCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarCategoriaActionPerformed

        Object[] cats = lstOutrasCats.getSelectedValues();

        List<Categoria> catReg = registro.getCategoriaCollection();
        for (int i = 0; i < cats.length; i++) {
            Categoria categoria = (Categoria) cats[i];
            catReg.add(categoria);
        }
        registro.setCategoriaCollection(catReg);
        loadCategoriaList();
    }//GEN-LAST:event_btnAdicionarCategoriaActionPerformed

    private void btMapaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMapaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btMapaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btMapa;
    private javax.swing.JButton btnAdicionarCategoria;
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnRemoverCategoria;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox cbCidade;
    private javax.swing.JComboBox cbDDD;
    private javax.swing.JComboBox cbEstado;
    private javax.swing.JComboBox cbPeso;
    private dialogs.ImagePanel imagePanel1;
    private dialogs.ImagePanelDlg imgIconeMob;
    private dialogs.ImagePanelDlg imgIconeWeb;
    private dialogs.ImagePanelDlg imgImagemMob;
    private dialogs.ImagePanelDlg imgImagemWeb;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JList lstCatAtuais;
    private javax.swing.JList lstOutrasCats;
    private javax.swing.JPanel tabCategoria;
    private javax.swing.JPanel tabImagem;
    private javax.swing.JPanel tabTelefone;
    private javax.swing.JPanel tbEndereco;
    private javax.swing.JPanel tbGeral;
    private javax.swing.JTextField txBairro;
    private javax.swing.JTextField txEmail;
    private javax.swing.JTextField txNome;
    private javax.swing.JTextField txNumero;
    private javax.swing.JTextArea txResumoMob;
    private javax.swing.JTextArea txResumoWeb;
    private javax.swing.JTextField txRua;
    private javax.swing.JTextField txTelefone1;
    private javax.swing.JTextField txTelefone2;
    private javax.swing.JTextArea txTextoMob;
    private javax.swing.JTextArea txTextoWeb;
    private javax.swing.JTextField txtSite;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the reg
     */
    public Registro getRegistro() {
        return registro;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof TelaRegistro) {
            if (((TelaRegistro) obj).getRegistro().getRegistroId() == null) {
                return true;
            }
            if (registro == null) {
                return true;
            }
            if (registro.getRegistroId() == null) {
                return true;
            }
            return ((TelaRegistro) obj).getRegistro().getRegistroId().intValue() == registro.getRegistroId().intValue() ? true : false;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public String toString() {
        if (registro != null) {
            return registro.toString();
        }
        return "Registro NULO " + super.toString();
    }
}
